class TemplatesController < ApplicationController
  #record_select :per_page => 5, :search_on => :tag_list
  @@templates_per_page = 50

  active_scaffold do |config|
    config.columns = :title, :preview, :filename, :tag_list, :related_templates

    list.columns.exclude :related_templates
    create.columns.exclude :related_templates
    update.columns.exclude :related_templates
    show.columns.exclude :filename
  end

  def select
    @selection = params[:id]
    limit = (params[:limit] || @@templates_per_page).to_i
    offset = (params[:offset] || 0).to_i
    options = {:limit => limit, :offset => offset}

    @templates = (params[:tags]) ? Template.find_tagged_with(params[:tags], options) : 
      Template.find(:all, options)
    @offset = limit + offset
    @limit = (@templates.length < limit) ? 0 : limit

    render :layout => false
  end

  def browse
    @base_templates = Template.find_tagged_with("基本")
    @related_templates = Template.find_tagged_with(params[:tag_list])
    render :layout => false
  end

  # active_scaffold callbacks
  def conditions_for_collection()
  end

  def before_create_save(record)
  end

  def after_create_save(record)
  end
  
  def before_update_save(record)
  end

  def after_update_save(record)
  end
end
